package com.unhz.taigu.controller.shiro.filter;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by cxg on 2017/8/10 0010.
 *
 * @Author 曹显贵
 * @Date 2017/8/10 0010 18:03
 */
public class ShiroSessionListener extends SessionListenerAdapter {
    Logger logger= LoggerFactory.getLogger(ShiroSessionListener.class);

    @Override
    public void onStart(Session session) {//会话创建时触发
        logger.debug("会话创建：" + session.getId());

    }
    public void onExpiration(ServletResponse res,Session session)throws IOException {//会话过期时触发
        HttpServletResponse response=(HttpServletResponse)res;
        logger.debug("会话过期：" + session.getId());
        response.sendRedirect("login.jsp");

    }
    public void onStop(Session session,ServletResponse res)throws IOException {//退出时触发
        HttpServletResponse response=(HttpServletResponse)res;
        logger.info("会话停止：" + session.getId());
        response.sendRedirect("login.jsp");
    }
}
